<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增设备消息绑定')"/>
    <style>
        .alert-secondary {
            color: #ff3939;
            background-color: #fdebeb;
        }
        .add-form-box{
            width: 1000px;
            margin:0 auto;
        }
        .btn-footer{
            text-align: right;
            width: calc(100% - 74px);
        }
    </style>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content add-form-box pt-md">
    <form class="form-horizontal" id="form-mgt-add">

        <div class="form-group">
            <div class="col-sm-9 col-sm-offset-2">
                <div class="alert alert-info test1" id="tips">
                    <div class="alert-text">
                        <i class=" fa-warning fa"></i>【温馨提示】<br>1、主要用于当检查到设备发生告警时，从而自动生成任务，会给在该页面绑定对应设备类型的责任人和相关人发送站内信消息。
                        <br>2、设备类型首次关联将默认设为责任人，同一设备类型只可设置一名责任人
                    </div>
                </div>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">设备类型：</label>
            <div class="col-sm-8">
                <select name="deviceType" class="form-control" th:with="type=${@dict.getType('gy_device_type')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">工单责任人：</label>
            <div class="col-sm-8">
                <input id="userId" name="userId" class="form-control" type="hidden">

                <div class="input-group">
                    <input class="form-control" type="text" onclick="selectDeptUserCallBack()" name="user.userName"
                           readonly="true" id="userName" required>
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否设为责任人：</label>
            <div class="col-sm-8">
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="isPrincipal" id="principal" value="1">是否设为责任人
                    </label>
                </div>
            </div>
        </div>

    </form>
    <div class="btn-action-wrap">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保
            存
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-secondary" onclick="closeItem()"><i class="fa fa-times"></i>关 闭
        </button>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "gy/mgt"
    $("#form-mgt-add").validate({
        focusCleanup: true
    });

    function selectDeptUserCallBack() {
        var options = {
            title: '选择用户',
            width: "1200",
            height: "700",
            url: prefix + "/getDeptUser",
            callBack: doSubmit2
        };
        $.modal.openOptions(options);
    }

    function doSubmit2(index, layero) {

        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }

        $('#userId').val(rows.join());
        $.operate.post(prefix + "/exists", $('#form-mgt-add').serialize(), (res) => {
            if (res.code == 0) {
                $('#userName').val(res.data.userName);
                $.modal.close(index);
            } else {
                $('#userName').val("");
                $('#userId').val("");
                $.modal.msgError(res.msg);
            }
        });
    }

    function submitHandler() {
        if ($("#userName").val() == "") {
            $.modal.alertWarning("请选择工单责任人");
            return;
        }
        if ($.validate.form()) {
            $.operate.saveTab(prefix + "/add", $('#form-mgt-add').serialize());
        }
    }
</script>
</body>
</html>
